#ifndef UTILS_H
#define UTILS_H

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

/* report error/debug information */
int report_msg(int retcode, const char* msg);
int report_msg_with_newline(int retcode, const char* msg);

typedef struct _CharBuf {
    char* buf;
    int len;
    int cursor;
    int delta;
} CharBuf;
  
int charbuf_init(CharBuf* cb, int len, int delta);
int charbuf_isempty(CharBuf* cb);
int charbuf_append_char(CharBuf* cb, char ch);
int charbuf_append_substr(CharBuf* cb, const char* src, int start, int end);
int charbuf_append_str(CharBuf* cb, const char* src);
int charbuf_fill_substr(CharBuf* cb, const char* src, int start, int end);
int charbuf_fill_str(CharBuf* cb, const char* src);
void charbuf_clear(CharBuf* cb);
void charbuf_zerotail(CharBuf* cb);
void charbuf_free(CharBuf* cb);
  
  
#ifdef __cplusplus
}
#endif // __cplusplus

#endif // UTILS_H
